package com.zlz.ddns.seddns.config;

import com.zlz.ddns.seddns.service.DDnsService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Component
public class TaskConfig {
    @Resource
    private DDnsService dnsService;

    @Scheduled(fixedRate = 5000) // 每隔5秒执行一次
    public void printCurrentTime() {
        try {
            LocalDateTime dateTime = LocalDateTime.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            System.out.println("Current time: " + formatter.format(dateTime));
            dnsService.refreshTencentCloudDNSPod();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
